#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
@author zyx
@since 2022/2/13 16:52
@file: c02_多线程.py
"""

import requests
import time
from threading import Thread  # 线程模块

start = time.time()  # 程序执行开始的时间
urls = ['http://127.0.0.1:5000/bobo',
        'http://127.0.0.1:5000/tom',
        'http://127.0.0.1:5000/jay']


def get_request(url):
    page_text = requests.get(url=url).text
    print(len(page_text))


ts = []
for url in urls:
    t = Thread(target=get_request, args=(url,))
    ts.append(t)
    t.start()

for t in ts:  # 让主线程等在所有的子线程结束后再结束
    t.join()

print('总耗时：', time.time() - start)  # 程序运行的总耗时
